package com.cloud.demo.user.controller;


import com.alibaba.fastjson.JSON;
import com.cloud.demo.common.result.BaseResult;
import com.cloud.demo.user.config.GitAutoRefreshConfig;
import com.cloud.demo.user.config.GitConfig;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.support.StandardServletEnvironment;

import javax.annotation.Resource;

/**
 * 类说明
 *
 * @author szj
 * @date 2021/7/15
 */
@Api(value = "TestController")
@RestController
@RequestMapping("/test")
@Slf4j
@RefreshScope
public class TestController {
    @Resource
    private GitConfig gitConfig;
    @Resource
    private GitAutoRefreshConfig gitAutoRefreshConfig;
    @Resource
    private StandardServletEnvironment environment;

    @RequestMapping(value = "success", method = RequestMethod.GET)
    @ApiOperation("test-success")
    public BaseResult<String> test() {
        String[] activeProfiles = environment.getActiveProfiles();
        for (String activeProfile : activeProfiles) {
            log.info("Environment environment:{}", activeProfile);
        }
        log.info("test...");
        return new BaseResult<>("SUCCESS");
    }

    @ApiOperation("show")
    @GetMapping(value = "show")
    public BaseResult<GitConfig> show(){
        return new BaseResult<>(gitConfig);
    }

    @ApiOperation("showAuto")
    @GetMapping(value = "showAuto")
    public BaseResult<GitAutoRefreshConfig> showAuto(){
        return new BaseResult<>(gitAutoRefreshConfig);
    }
}
